// AITArea.cpp: implementation of the AITArea class.
//
//////////////////////////////////////////////////////////////////////

#include "AITArea.h"
#include <GL/glut.h>
#include <gl/glaux.h> // Header file for the GLaux library.  
#include <iostream.h>

#define ROW 5
#define COL 5

static float controls[ROW][COL][3];

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

AITArea::AITArea()
{
	this->WidthAIT = 10.0;
	this->HightAIT = 10.0;
	this->Type = 0;
}

AITArea::AITArea(float width,float hight,int type)
{
	this->WidthAIT = width;
	this->HightAIT = hight;
	this->Type = type;
}

AITArea::~AITArea()
{
	
}

AITArea::Intial(float width,float hight,int type)
{
	this->WidthAIT = width;
	this->HightAIT = hight;
	this->Type = type;
}

/////////////////////////////////////////////////////////////////////
//	Rander
////////////////////////////////////////////////////////////////////

AITArea::Render(float x_pos,float y_pos,float z_pos)
{
	float cx,cy,cz;
	cx = x_pos - (this->WidthAIT/2); 
	cy = y_pos - (this->HightAIT/2);
	cz = z_pos;

	this->CalcControlPoints();

	glPushMatrix();
	//glRotatef(90.0, 1.0, 0.0, 0.0);
	glTranslatef(cx,cy,cz);
	this->DrawAITArea();
	glPopMatrix();
}

AITArea::CalcControlPoints() //control must be 3D float array
{
	int i,j;
	float segRow = (float)(this->HightAIT/(ROW-1));
	float segCol = (float)(this->WidthAIT/(COL-1));

	//cout<<segRow<<endl;

	for(i=0;i<ROW;i++)
	{
		for(j=0;j<COL;j++)
		{
      controls[i][j][0] = i*segRow; //X
			//cout<<"X : "<< controls[i][j][0] <<endl;
			controls[i][j][1] = j*segCol; //Y
			controls[i][j][2] = 0; //Z
		}
	}
}


AITArea::DrawAITArea()
{
	int i,j;

	glPushMatrix();

	  // Draw yellow control points.
    glColor3f(1.0, 1.0, 0.0);
		glPointSize(5.0);
    glBegin(GL_POINTS);
      for (i = 0; i < ROW; i++)
         for (j = 0; j < COL; j++)
            glVertex3fv(controls[i][j]);
    glEnd();

		//Draw Squal size = WidthAIT * HightAIT 

		// Specify and enable the Bezier surface.
    glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, COL, 0, 1, 3*COL, ROW, controls[0][0]); 
    glEnable(GL_MAP2_VERTEX_3); 

    // Make a mesh approximation of the Bezier surface.
    glColor3f (1.0, 1.0, 1.0);
    glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);
    glEvalMesh2(GL_LINE, 0, 20, 0, 20);

	glPopMatrix();
}

/////////////////////////////////////////////////////////////////////////
// Type Of Area
////////////////////////////////////////////////////////////////////////
AITArea::setAType(int type)
{
	this->Type = type;
}

AITArea::getAType()
{
	return (this->Type);
}
